//
//  AddressBookExampleViewController.m
//  AddressBookExample
//

#import "AddressBookExampleViewController.h"

@implementation AddressBookExampleViewController

- (void)logPerson:(ABRecordRef)person {
	CFStringRef name = ABRecordCopyCompositeName(person);
	ABRecordID recId = ABRecordGetRecordID(person);
	NSLog(@"Person Name: %@ RecordID:%d", name, recId);
}

- (void)logGroup:(ABRecordRef)group {
	CFStringRef name = ABRecordCopyValue(group, kABGroupNameProperty);
	ABRecordID recId = ABRecordGetRecordID(group);
	NSLog(@"Group Name: %@ RecordID: %d", name, recId);
}

- (void)viewDidLoad {
    [super viewDidLoad];
	
	ABAddressBookRef addressBook = ABAddressBookCreate();
	CFArrayRef allPeople = ABAddressBookCopyArrayOfAllPeople(addressBook);
	CFArrayRef allGroups = ABAddressBookCopyArrayOfAllGroups(addressBook);
	for (id person in (NSArray *)allPeople)
		[self logPerson:person];
	for (id group in (NSArray *)allGroups)
		[self logGroup:group];
	CFRelease(allGroups);
	CFRelease(allPeople);
	CFRelease(addressBook);
}

- (void)dealloc {
    [super dealloc];
}

@end
